from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-07 14:11:06.231185
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 07, Sep, 2022
Time: 14:11:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.3500
Nobs: 772.000 HQIC: -50.6834
Log likelihood: 9875.50 FPE: 7.90526e-23
AIC: -50.8919 Det(Omega_mle): 7.04063e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299034 0.054392 5.498 0.000
L1.Burgenland 0.106620 0.036224 2.943 0.003
L1.Kärnten -0.106867 0.019247 -5.552 0.000
L1.Niederösterreich 0.205420 0.075799 2.710 0.007
L1.Oberösterreich 0.113872 0.073367 1.552 0.121
L1.Salzburg 0.253458 0.038764 6.538 0.000
L1.Steiermark 0.036479 0.050538 0.722 0.470
L1.Tirol 0.107086 0.040946 2.615 0.009
L1.Vorarlberg -0.060699 0.035213 -1.724 0.085
L1.Wien 0.050290 0.065182 0.772 0.440
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059360 0.112944 0.526 0.599
L1.Burgenland -0.034317 0.075218 -0.456 0.648
L1.Kärnten 0.047359 0.039967 1.185 0.236
L1.Niederösterreich -0.176482 0.157395 -1.121 0.262
L1.Oberösterreich 0.394956 0.152346 2.593 0.010
L1.Salzburg 0.290072 0.080494 3.604 0.000
L1.Steiermark 0.106069 0.104942 1.011 0.312
L1.Tirol 0.314524 0.085025 3.699 0.000
L1.Vorarlberg 0.027220 0.073119 0.372 0.710
L1.Wien -0.021588 0.135350 -0.159 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191787 0.027939 6.864 0.000
L1.Burgenland 0.089396 0.018607 4.804 0.000
L1.Kärnten -0.008530 0.009887 -0.863 0.388
L1.Niederösterreich 0.260739 0.038935 6.697 0.000
L1.Oberösterreich 0.133923 0.037686 3.554 0.000
L1.Salzburg 0.046079 0.019912 2.314 0.021
L1.Steiermark 0.018211 0.025960 0.702 0.483
L1.Tirol 0.093127 0.021033 4.428 0.000
L1.Vorarlberg 0.058334 0.018087 3.225 0.001
L1.Wien 0.118045 0.033482 3.526 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108202 0.028420 3.807 0.000
L1.Burgenland 0.047441 0.018927 2.507 0.012
L1.Kärnten -0.014884 0.010057 -1.480 0.139
L1.Niederösterreich 0.191580 0.039605 4.837 0.000
L1.Oberösterreich 0.289970 0.038334 7.564 0.000
L1.Salzburg 0.111628 0.020254 5.511 0.000
L1.Steiermark 0.102998 0.026406 3.901 0.000
L1.Tirol 0.110599 0.021394 5.170 0.000
L1.Vorarlberg 0.069699 0.018399 3.788 0.000
L1.Wien -0.017972 0.034058 -0.528 0.598
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131003 0.051604 2.539 0.011
L1.Burgenland -0.050860 0.034367 -1.480 0.139
L1.Kärnten -0.040237 0.018261 -2.203 0.028
L1.Niederösterreich 0.170062 0.071913 2.365 0.018
L1.Oberösterreich 0.139339 0.069606 2.002 0.045
L1.Salzburg 0.287714 0.036778 7.823 0.000
L1.Steiermark 0.033737 0.047948 0.704 0.482
L1.Tirol 0.161712 0.038848 4.163 0.000
L1.Vorarlberg 0.100793 0.033408 3.017 0.003
L1.Wien 0.068609 0.061841 1.109 0.267
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056504 0.041081 1.375 0.169
L1.Burgenland 0.040186 0.027359 1.469 0.142
L1.Kärnten 0.050653 0.014537 3.484 0.000
L1.Niederösterreich 0.221113 0.057249 3.862 0.000
L1.Oberösterreich 0.282588 0.055412 5.100 0.000
L1.Salzburg 0.045498 0.029278 1.554 0.120
L1.Steiermark -0.000609 0.038170 -0.016 0.987
L1.Tirol 0.147621 0.030926 4.773 0.000
L1.Vorarlberg 0.073001 0.026595 2.745 0.006
L1.Wien 0.084246 0.049230 1.711 0.087
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180332 0.049190 3.666 0.000
L1.Burgenland -0.006279 0.032760 -0.192 0.848
L1.Kärnten -0.061259 0.017407 -3.519 0.000
L1.Niederösterreich -0.083949 0.068550 -1.225 0.221
L1.Oberösterreich 0.196034 0.066351 2.954 0.003
L1.Salzburg 0.056668 0.035057 1.616 0.106
L1.Steiermark 0.231336 0.045705 5.061 0.000
L1.Tirol 0.493702 0.037031 13.332 0.000
L1.Vorarlberg 0.048122 0.031845 1.511 0.131
L1.Wien -0.052553 0.058949 -0.892 0.373
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166243 0.056461 2.944 0.003
L1.Burgenland -0.010262 0.037602 -0.273 0.785
L1.Kärnten 0.067147 0.019979 3.361 0.001
L1.Niederösterreich 0.206378 0.078682 2.623 0.009
L1.Oberösterreich -0.071050 0.076158 -0.933 0.351
L1.Salzburg 0.211508 0.040239 5.256 0.000
L1.Steiermark 0.115698 0.052461 2.205 0.027
L1.Tirol 0.071903 0.042504 1.692 0.091
L1.Vorarlberg 0.121622 0.036552 3.327 0.001
L1.Wien 0.122395 0.067662 1.809 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357617 0.032660 10.950 0.000
L1.Burgenland 0.005363 0.021750 0.247 0.805
L1.Kärnten -0.023345 0.011557 -2.020 0.043
L1.Niederösterreich 0.214779 0.045513 4.719 0.000
L1.Oberösterreich 0.187918 0.044053 4.266 0.000
L1.Salzburg 0.046307 0.023276 1.989 0.047
L1.Steiermark -0.015531 0.030346 -0.512 0.609
L1.Tirol 0.106576 0.024586 4.335 0.000
L1.Vorarlberg 0.073567 0.021143 3.479 0.001
L1.Wien 0.048109 0.039139 1.229 0.219
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040053 0.148450 0.192634 0.157144 0.124371 0.113226 0.065978 0.222545
Kärnten 0.040053 1.000000 -0.004039 0.132549 0.041620 0.095674 0.430578 -0.052279 0.100282
Niederösterreich 0.148450 -0.004039 1.000000 0.337878 0.151724 0.298386 0.108202 0.183433 0.323718
Oberösterreich 0.192634 0.132549 0.337878 1.000000 0.228792 0.330346 0.172928 0.167886 0.265242
Salzburg 0.157144 0.041620 0.151724 0.228792 1.000000 0.147920 0.122621 0.147437 0.133556
Steiermark 0.124371 0.095674 0.298386 0.330346 0.147920 1.000000 0.151828 0.138625 0.079500
Tirol 0.113226 0.430578 0.108202 0.172928 0.122621 0.151828 1.000000 0.115138 0.153492
Vorarlberg 0.065978 -0.052279 0.183433 0.167886 0.147437 0.138625 0.115138 1.000000 0.006749
Wien 0.222545 0.100282 0.323718 0.265242 0.133556 0.079500 0.153492 0.006749 1.000000